package model

import (
	"rabbit_love/src/utils"
	"time"
)

type UserTable struct {
	utils.TimeMixin

	Email    string    `gorm:"UNIQUE; column:email; type:VARCHAR(32)" json:"email"`
	NickName string    `gorm:"column:nickName; type:VARCHAR(64)" json:"nickName"`
	UserName string    `gorm:"UNIQUE; column:userName; type:VARCHAR(32)" json:"userName"`
	PassWord string    `gorm:"column:passWord; type:VARCHAR(64)" json:"passWord"`
	IconUrl  string    `gorm:"column:iconUrl; type:VARCHAR(256); default:null" json:"iconUrl"`
	BirthDay time.Time `gorm:"column:birthDay; type:TIMESTAMP(6); default:null" json:"birthDay"`

	Sex string `gorm:"column:sex; type:ENUM('男孩','女孩', '未知'); default:'未知'; NOT NULL" json:"sex"`

	LoverRelationTableId int64 `gorm:"column:loverRelationId;default:null"`
	LoverNickNameTable   LoverNickNameTable

	AnniversaryTable []AnniversaryTable

	FromChat []ChatTable `gorm:"foreignKey:From"` // 自己发出的悄悄话
	ToChat   []ChatTable `gorm:"foreignKey:To"`   // 自己收到悄悄话

	FromLoverInvite []LoverInviteTable `gorm:"foreignKey:From"` // 自己发出的邀请信息
	ToLoverInvite   []LoverInviteTable `gorm:"foreignKey:To"`   // 自己收到的邀请信息
}

func (*UserTable) TableName() string {
	return "user_table"
}

type AcceptType int

const (
	None  AcceptType = 0 // 没有相应
	Allow AcceptType = 1 // 同意邀请
	Deny  AcceptType = 2 // 拒绝
)

type LoverInviteTable struct {
	utils.TimeMixin

	From   int64      `gorm:"column:from; type:INT(16); NOT NULL" json:"from"`         // 邀请用户ID
	To     int64      `gorm:"column:to; type:INT(16); NOT NULL" json:"to"`             // 被邀请用户ID
	Read   bool       `gorm:"column:read; type:TINYINT(2); default:0" json:"read"`     // 是否查看 默认没有查看
	Accept AcceptType `gorm:"column:accept; type:TINYINT(2); default:0" json:"accept"` // 是否接受 默认没有回应
}

func (*LoverInviteTable) TableName() string {
	return "lover_invite_table"
}

type LoverNickNameTable struct {
	utils.TimeMixin

	LoverRelationTableId int64  `gorm:"column:loverRelationId"` // 情侣关系id
	UserTableId          int64  `gorm:"column:userId"`          // 自己的id
	TargetNickName       string `gorm:"column:targetNickName"`  // 给恋人起的爱称
}

func (*LoverNickNameTable) TableName() string {
	return "lover_nick_name_table"
}

type LoverRelationTable struct {
	utils.TimeMixin

	UserTable          []UserTable
	LoverNickNameTable []LoverNickNameTable
	AnniversaryTable   []AnniversaryTable
	LoverName          string    `gorm:"column:loverName; type:VARCHAR(64); default:null" json:"loverName"`
	StartTime          time.Time `gorm:"column:startTime; type:TIMESTAMP(6); default:null" json:"startTime"`

	Daily []DailyTable `json:"daily"`
}

func (*LoverRelationTable) TableName() string {
	return "lover_relation_table"
}
